﻿using EFCoreLockStudy1.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace EFCoreLockStudy1;

public class SqlDbContext:DbContext
{
    public DbSet<House>  Houses { get; set; }
    private static ILoggerFactory loggerFactory = LoggerFactory.Create(builder=>builder.AddConsole());
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        optionsBuilder.UseSqlServer("server=localhost;database=db0802;integrated security=true; encrypt=false");
        optionsBuilder.UseLoggerFactory(loggerFactory);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
    }
}
